package com.engine.taskmask;
import com.engine.taskmask.persistence.*;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class UpdateTaskServlet extends HttpServlet {
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
				UserService userService = UserServiceFactory.getUserService();
				User user = userService.getCurrentUser();
				if (user == null) {
					resp.sendRedirect("/index.jsp");
					return;
				}
				resp.sendRedirect("/index.jsp");
				
				/*if (user==null){
					resp.sendRedirect("/rec_list.jsp");
					return;
				}

				if (req.getParameter("id")==null){
					resp.sendRedirect("/rec_list.jsp");
					return;
				}

				long id=Long.parseLong(req.getParameter("id"));	        	
				PersistenceManager pm = PMF.get().getPersistenceManager();
				try {
					 //pm.currentTransaction().begin();
					iTask rec=pm.getObjectById(iTask.class,id);
					if (rec.getUser_id().equals(user.getUserId())){
						if (req.getParameter("id")==null){
							resp.sendRedirect("/rec_list.jsp");
							return;
						}
						rec.setTaskTitle(req.getParameter("title"));
						rec.setTaskLocation(req.getParameter("location"));
						rec.setTaskCategory(req.getParameter("category"));
						rec.setDate_s(req.getParameter("date"));
						rec.setTaskNotes(req.getParameter("notes"));
						rec.setTaskPriority(req.getParameter("priority"));
						if((req.getParameter("flagged")!=null)&&(req.getParameter("flagged").equals("flagged")))
							rec.setTaskFlagged(true);
						else
							rec.setTaskFlagged(false);
						pm.makePersistent(rec);
						pm.currentTransaction().commit();
					}
				}
				catch (Exception e) {
					pm.currentTransaction().rollback();
					 throw new RuntimeException(e);
				}
				finally{
					pm.close();
				}

				resp.sendRedirect("/recview.jsp?id=("+id+")");*/
			}
}
